﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PostSharp.Aspects;

namespace EBookStore.AOP
{
    [Serializable]    
    class NotNullPropertySet:LocationInterceptionAspect
    {
        /// <summary>
        /// Validates that value won't be set to null object.
        /// </summary>
        /// <param name="args"></param>
        public override void OnSetValue(LocationInterceptionArgs args)
        {
            if( args.Value == null)                
                throw new NullReferenceException("Value can't be null");
        }        
    }


    [Serializable] 
    class AboveZeroPropertySet : LocationInterceptionAspect
    {
        /// <summary>
        /// Validates that value won't be set to null object.
        /// </summary>
        /// <param name="args"></param>
        public override void OnSetValue(LocationInterceptionArgs args)
        {
            decimal num = Convert.ToDecimal(args.Value);
            if (num <= 0)
                throw new Exception("Value can't be less or equal to zero");
        }
    }


    [Serializable]
    class NotStringNullOrEmptyPropertySet : LocationInterceptionAspect
    {
        /// <summary>
        /// Validates that value won't be set to null object.
        /// </summary>
        /// <param name="args"></param>
        public override void OnSetValue(LocationInterceptionArgs args)
        {            
            if (string.IsNullOrEmpty(args.Value.ToString()))
                throw new Exception("string can't be null or empty");
        }
    }
}
